package com.catmiao.spark.rdd.operator.action

import org.apache.spark.{SparkConf, SparkContext}

/**
 * @title: RDD_Operator_01_action
 * @projectName spark_study
 * @description: TODO
 * @author ChengMiao
 * @date 2024/2/22 22:47
 */
object RDD_Operator_07_action {

  def main(args: Array[String]): Unit = {
    val sparkCon = new SparkConf().setMaster("local[*]").setAppName("rdd")

    val sparkContext = new SparkContext(sparkCon)

    //    val rdd = sparkContext.makeRDD(List(1,2,3,4),2)
    val rdd = sparkContext.makeRDD(List(
      1, 2, 3, 4
    ))

    val user = new User

    // 闭包检测：rdd算子中传递到函数是会包含闭包操作，那么功能【即便没有执行也可以判断】
    rdd.foreach(
      item => {
        println("age =" + (user.age + item))
      }
    )


    sparkContext.stop()

  }


   class User extends Serializable {
//  case class User { // 样例类编译时会自动混入序列化特质
    var age: Int = 30
  }

}
